var updateTreatmentUnitl = {
    id: "updateTreatmentUnitlTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

updateTreatmentUnitl.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '', field: 'reservationsId', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '客户姓名', field: 'customerName',  align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '手机号码', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '门诊', field: 'outpatientName', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '原科室', field: 'ytreatmentUnitl', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '新科室', field: 'xtreatmentUnitl', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '变更理由', field: 'remarks', align: 'center', valign: 'middle', sortable: true,width: 120,
            formatter: function (value, row, index) {
                return '<span title="'+value+'">'+value+'</span>'
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
        {
            title: '提交时间', field: 'addTime', align: 'center', valign: 'middle', sortable: true,width: 170,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '审核状态', field: 'status', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '审核人', field: 'updatePeople', align: 'center', valign: 'middle', sortable: true,width: 120},
        {
            title: '审核时间', field: 'updateTime', align: 'center', valign: 'middle', sortable: true,width: 170,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '审核结果', field: 'isno', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '审核备注', field: 'remarkss', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '操作', field: '', align: 'center', valign: 'middle', sortable: true,width: 150,
            formatter: function (value, row, index) {
                if(row.status=='待审核'){
                    var ids = row.id+","+row.reservationsId;
                    return '<span onclick="updateTreatmentUnitl.modify(' + "'" + ids+ "'" + ')" style="cursor: pointer">【修改科室审核】</span>'
                }else if(row.status=='已审核'){
                    return '<span>完成</span>'
                }
            }
        }
    ];
};

updateTreatmentUnitl.modify = function (ids) {
    var index = layer.open({
        type: 2,
        title: '修改科室',
        area: ['40%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/updateTreatmentUnit/' + ids
    });
    this.layerIndex = index;
};


updateTreatmentUnitl.formParams = function () {
    var queryData = {};
    queryData['outpatientName'] = $("#outpatientName").val();
    queryData['status'] = $("#status").val();
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['sreach'] = $("#sreach").val();
    return queryData;
};

updateTreatmentUnitl.resetSearch = function () {
    $("#outpatientName").val("");
    $("#status").val("");
    $("#startTime").val("");
    $("#endTime").val("");
    $("#sreach").val("");
    updateTreatmentUnitl.search();
};

updateTreatmentUnitl.search = function () {
    updateTreatmentUnitl.table.refresh({query: updateTreatmentUnitl.formParams()});
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

$(function () {
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endTime").value =myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = updateTreatmentUnitl.initColumn();
    var table = new BSTable(updateTreatmentUnitl.id, "/reservationsLog/updateTreatmentUnitlList", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(updateTreatmentUnitl.formParams());
    updateTreatmentUnitl.table = table.init();
    updateTreatmentUnitl.search();
    $("#zoom").click(function () {
        if ($("#zoom > span").hasClass('tabMark')) {
            $("#zoom > span").removeClass('tabMark').html('条件展开');
            $("#zoom > img,.divFlex").toggle();
            $(document).ready(function () {
                $('#updateTreatmentUnitlTable').bootstrapTable('resetView', {height: $(window).height() - 76});
            });
        } else {
            $("#zoom > span").addClass('tabMark').html('条件收起');
            $("#zoom > img,.divFlex").toggle();
            $(document).ready(function () {
                $('#updateTreatmentUnitlTable').bootstrapTable('resetView', {height: $(window).height() - 137});
            });
        }
    });
    $(document).on('click','#laydate_clear,#laydate_today,#laydate_ok',function () {updateTreatmentUnitl.search();});
    checkDate = function () {updateTreatmentUnitl.search();};
});